﻿CREATE PROCEDURE [dbo].[Proc_GetCancelAppointInfo]       
 @SheetIDs varchar(max)      
AS      
BEGIN
	--搜索基础数据插入临时表#Schedule 
	 select 
	     a.VisitingNo 
        ,'' as FeeTypeName 
        ,a.SheetID 
        ,b.ExamProject 
        ,'' AS ReqValidDateHigh --20120508
		,'' AS ReqValidDateLow --20120508
        ,'' as PriorityCode 
        ,'' as PriorityName 
        ,a.ReqSheetDate --201205061000
        ,a.ReqSheetDoctorID 
        ,a.ReqSheetDoctor 
        ,a.BillingDeptCode 
        ,a.BillingDeptName 
        ,'' AS VerifierDate --201205061000
        ,'' AS VerifierCode 
        ,'' AS VerifierName 
        ,a.OutPatientID 
        ,a.InPatientID 
        ,'' AS BabyID 
        ,CASE a.PatientStyle WHEN '0' THEN '1' WHEN '1' THEN '2' WHEN '2' THEN '3' ELSE '9' END AS PatientStyle  --1.门诊 2.急诊 3.住院 9.其他
        ,CASE a.PatientStyle WHEN '0' THEN '门诊' WHEN '1' THEN '急诊' WHEN '2' THEN '住院' ELSE '其他' END AS PatientStyleName 
        ,a.PatientID 
        ,a.PatientIdentityNo 
        ,a.MedicalCardNum 
        ,a.PatientName 
        ,a.PatientHomeTel 
        ,a.PatientSex 
        ,a.PatientHomeAddress 
        ,a.PatientBedNo 
        ,a.PatientWardNo 
        ,a.PatientWardName 
        ,'' AS LinChuangZhenDuan 
        ,a.PatientBirth --19870202
        ,a.PatientAge 
		,c.ItemCode
		,c.ExamProject as ItemName
		,'' as ExamMethodCode
		,c.ExamMethod
		,'' as ExamModalityCode
		,c.ExamModality
		,'' as ExamBodyPartCode
		,c.ExamBodyPart
		,c.ExamDeptCode
		,e.DeptName as ExamDeptName
	 from RequestInfo a      
	 inner join RequestExam b on a.SheetID=b.SheetID and a.RequestSheetStyle=b.RequestSheetStyle      
	 inner join ExamSource c on b.ItemCode=c.ItemCode and c.NeedSchedule=1   
	 inner join (select * from fn_split(@SheetIDs,',')) d on d.rvalue=a.SheetID
	 left join DepartmentInfo e on a.ExamDeptCode=e.DeptCode
END